home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / 80x0393.zip / MOUSE.ASM < prev    next >
Assembly Source File  |  1993-03-30  |  7KB  |  391 lines

  1. ; MOUSE.ASM (Turbo Assembler syntax)
  2. ; Assorted routines for interfacing to a Microsoft-compatible mouse driver.
  3. ; Public domain by Matthew Hildebrand (FidoNet 1:247/128.2)
  4. ; This module may be overlaid
  5.  
  6.  
  7. IDEAL
  8. P286
  9. MODEL    LARGE
  10.  
  11.  
  12.     CODESEG
  13.  
  14. ; resets the mouse driver.  Returns 1 if mouse installed, 0 if not
  15. ; char resetMouse(void);
  16.     PUBLIC    C    resetMouse
  17. PROC    C    resetMouse
  18.   xor    ax,ax
  19.   int    33h
  20.   cmp    ax,0FFFFh
  21.   jne    @@L1
  22.   mov    ax,1
  23.   retcode
  24.     @@L1:
  25.   xor    ax,ax
  26.   retcode
  27. ENDP
  28.  
  29. ; returns the number of buttons on the mouse
  30. ; CAUTION!  Also resets the mouse
  31. ; char getButtonsMouse(void);
  32.     PUBLIC    C    getButtonsMouse
  33. PROC    C    getButtonsMouse
  34.   xor    ax,ax
  35.   int    33h
  36.   mov    al,bl
  37.   xor    ah,ah
  38.   retcode
  39. ENDP
  40.  
  41. ; shows the mouse pointer
  42. ; void showMouse(void);
  43.     PUBLIC    C    showMouse
  44. PROC    C    showMouse
  45.   mov    ax,1
  46.   int    33h
  47.   retcode
  48. ENDP
  49.  
  50. ; hides the mouse pointer
  51. ; void hideMouse(void);
  52.     PUBLIC    C    hideMouse
  53. PROC    C    hideMouse
  54.   mov    ax,2
  55.   int    33h
  56.   retcode
  57. ENDP
  58.  
  59. ; returns the current mouse (x,y) coordinates
  60. ; void getPosMouse(int far *x, int far *y);
  61.     PUBLIC    C    getPosMouse
  62. PROC    C    getPosMouse
  63.     ARG    x:DATAPTR, y:DATAPTR
  64.   mov    ax,3
  65.   int    33h
  66.   les    bx,[x]
  67. ;  shr    cx,1                ; adjust for mode 13h bug
  68.   mov    [es:bx],cx
  69.   les    bx,[y]
  70.   mov    [es:bx],dx
  71.   leave
  72.   retcode
  73. ENDP
  74.  
  75. ; returns true if a button is pressed
  76. ; int buttonMouse(void);
  77.     PUBLIC    C    buttonMouse
  78. PROC    C    buttonMouse
  79.   mov    ax,3
  80.   int    33h
  81.   test    bl,1
  82.   jz    @@L1
  83.   mov    ax,1
  84.   retcode
  85.  
  86.     @@L1:
  87.   test    bl,2
  88.   jz    @@L2
  89.   mov    ax,2
  90.   retcode
  91.       @@L2:
  92.   test    bl,4
  93.   jz    @@L3
  94.   mov    ax,3
  95.   retcode
  96.       @@L3:
  97.   xor    ax,ax
  98.   retcode
  99. ENDP
  100.  
  101. ; returns true if the left button is pressed
  102. ; int leftButtonMouse(void);
  103.     PUBLIC    C    leftButtonMouse
  104. PROC    C    leftButtonMouse
  105.   mov    ax,3
  106.   int    33h
  107.   test    bl,1
  108.   jnz    @@L1
  109.   xor    ax,ax
  110.   retcode
  111.     @@L1:
  112.   mov    ax,1
  113.   retcode
  114. ENDP
  115.  
  116. ; returns true if the right button is pressed
  117. ; int rightButtonMouse(void);
  118.     PUBLIC    C    rightButtonMouse
  119. PROC    C    rightButtonMouse
  120.   mov    ax,3
  121.   int    33h
  122.   test    bl,2
  123.   jnz    @@L1
  124.   xor    ax,ax
  125.   retcode
  126.     @@L1:
  127.   mov    ax,1
  128.   retcode
  129. ENDP
  130.  
  131. ; returns true if the center button is pressed
  132. ; int centerButtonMouse(void);
  133.     PUBLIC    C    centerButtonMouse
  134. PROC    C    centerButtonMouse
  135.   mov    ax,3
  136.   int    33h
  137.   test    bl,4
  138.   jnz    @@L1
  139.   xor    ax,ax
  140.   retcode
  141.     @@L1:
  142.   mov    ax,1
  143.   retcode
  144. ENDP
  145.  
  146. ; sets the position of the mouse pointer
  147. ; void setPosMouse(unsigned x,unsigned y);
  148.     PUBLIC    C    setPosMouse
  149. PROC    C    setPosMouse
  150.     ARG    x:WORD, y:WORD
  151.   mov    ax,4
  152.   mov    cx,[x]
  153. ;  shl    cx,1                ; adjust for mode 13h bug
  154.   mov    dx,[y]
  155.   int    33h
  156.   leave
  157.   retcode
  158. ENDP
  159.  
  160. ; Returns the button press counter.
  161. ; unsigned buttonPressMouse(unsigned button, far *x, far *y);
  162.     PUBLIC    C    buttonPressMouse
  163. PROC    C    buttonPressMouse
  164.     ARG    button:WORD, x:DATAPTR, y:DATAPTR
  165.   mov    ax,5
  166.   mov    bx,[button]
  167.   dec    bx
  168.   int    33h
  169.   mov    ax,bx                ; save press counter for return
  170.   les    bx,[x]
  171. ;  shr    cx,1                ; Adjust for mode 13h bug
  172.   mov    [es:bx],cx            ; x coordinate
  173.   les    bx,[y]
  174.   mov    [es:bx],dx            ; y coordinate
  175.   leave
  176.   retcode
  177. ENDP
  178.  
  179. ; Returns the button release counter.
  180. ; unsigned buttonReleaseMouse(unsigned button, far *x, far *y);
  181.     PUBLIC    C    buttonReleaseMouse
  182. PROC    C    buttonReleaseMouse
  183.     ARG    button:WORD, x:DATAPTR, y:DATAPTR
  184.   mov    ax,6
  185.   mov    bx,[button]
  186.   dec    bx
  187.   int    33h
  188.   mov    ax,bx                ; save release counter for return
  189.   les    bx,[x]
  190. ;  shr    cx,1                ; Adjust for mode 13h bug
  191.   mov    [es:bx],cx            ; x coordinate
  192.   les    bx,[y]
  193.   mov    [es:bx],dx            ; y coordinate
  194.   leave
  195.   retcode
  196. ENDP
  197.  
  198. ; set the horizontal limits for the mouse pointer
  199. ; void setHorizLimitsMouse(unsigned min,unsigned max);
  200.     PUBLIC    C    setHorizLimitsMouse
  201. PROC    C    setHorizLimitsMouse
  202.     ARG    min:WORD, max:WORD
  203.   mov    ax,7
  204.   mov    cx,[min]
  205.   mov    dx,[max]
  206. ;  shl    dx,1                ; adjust for mode 13h bug
  207.   int    33h
  208.   leave
  209.   retcode
  210. ENDP
  211.  
  212. ; set the vertical limits for the mouse pointer
  213. ; void setVertLimitsMouse(unsigned min,unsigned max);
  214.     PUBLIC    C    setVertLimitsMouse
  215. PROC    C    setVertLimitsMouse
  216.     ARG    min:WORD, max:WORD
  217.   mov    ax,8
  218.   mov    cx,[min]
  219.   mov    dx,[max]
  220.   int    33h
  221.   leave
  222.   retcode
  223. ENDP
  224.  
  225. ; set the graphics pointer shape
  226. ; void setPointerMouse(int xoff,int yoff,void *p);
  227.     PUBLIC    C    setPointerMouse
  228. PROC    C    setPointerMouse
  229.     ARG    xOff:WORD, yOff:WORD, p:DATAPTR
  230.   mov    ax,9
  231.   mov    bx,[xOff]
  232.   mov    cx,[yOff]
  233.   les    dx,[p]
  234.   int    33h
  235.   leave
  236.   retcode
  237. ENDP
  238.  
  239. ; set a mouse pointer exclusion area.  The pointer is not displayed when
  240. ; inside the specified coordinates.  Only one is active at a time.
  241. ; Cancelled by a call to resetMouse() or showMouse()
  242. ; void setExclusionMouse(unsigned ulx,unsigned uly,unsigned lrx,unsigned lry);
  243.     PUBLIC    C    setExclusionMouse
  244. PROC    C    setExclusionMouse
  245.     ARG    ulx:WORD, uly:WORD, lrx:WORD, lry:WORD
  246.   push    si di
  247.   mov    ax,10
  248.   mov    cx,[ulx]
  249. ;  shr    cx,1                ; adjust for mode 13h bug (?)
  250.   mov    dx,[uly]
  251.   mov    si,[lrx]
  252. ;  shr    si,1                ; adjust for mode 13h bug (?)
  253.   mov    di,[lry]
  254.   int    33h
  255.   pop    di si
  256.   leave
  257.   retcode
  258. ENDP
  259.  
  260. ; Set the mickeys to pixels ratio (mickeys/8 pixels)
  261.     PUBLIC    C    setRatioMouse
  262. PROC    C    setRatioMouse
  263.       ARG    horiz:WORD, vert:WORD
  264.   mov    ax,000Fh
  265.   mov    cx,[horiz]
  266.   mov    dx,[vert]
  267.   int    33h
  268.   leave
  269.   retcode
  270. ENDP
  271.  
  272. ; Returns the size of the mouse save state buffer
  273.     PUBLIC    C    getSaveSizeMouse
  274. PROC    C    getSaveSizeMouse
  275.   mov    ax,0015h
  276.   int    33h
  277.   mov    ax,bx
  278.   retcode
  279. ENDP
  280.  
  281. ; Save the current state of the mouse driver
  282.     PUBLIC    C    saveStateMouse
  283. PROC    C    saveStateMouse
  284.     ARG    data:DATAPTR
  285.   mov    ax,0016h
  286.   les    dx,[data]
  287.   int    33h
  288.   leave
  289.   retcode
  290. ENDP
  291.  
  292. ; Restore the state of the mouse driver
  293.     PUBLIC    C    restoreStateMouse
  294. PROC    C    restoreStateMouse
  295.     ARG    data:DATAPTR
  296.   mov    ax,0017h
  297.   les    dx,[data]
  298.   int    33h
  299.   leave
  300.   retcode
  301. ENDP
  302.  
  303. ; Set the mouse sensitivity (mickeys/8 pixels)
  304.     PUBLIC    C    setSensitivityMouse
  305. PROC    C    setSensitivityMouse
  306.     ARG    horiz:WORD, vert:WORD, doubleSpeed:WORD
  307.   mov    ax,001Ah
  308.   mov    bx,[horiz]
  309.   mov    cx,[vert]
  310.   mov    dx,[doubleSpeed]
  311.   int    33h
  312.   leave
  313.   retcode
  314. ENDP
  315.  
  316. ; Get the mouse sensitivity (mickeys/8 pixels)
  317.     PUBLIC    C    getSensitivityMouse
  318. PROC    C    getSensitivityMouse
  319.       ARG    horiz:DATAPTR, vert:DATAPTR, doubleSpeed:DATAPTR
  320.   push    di
  321.  
  322.   mov    ax,001Bh
  323.   int    33h
  324.   les    di,[horiz]
  325.   mov    [es:di],bx
  326.   les    di,[vert]
  327.   mov    [es:di],cx
  328.   les    di,[doubleSpeed]
  329.   mov    [es:di],dx
  330.  
  331.   pop    di
  332.   leave
  333.   retcode
  334. ENDP
  335.  
  336. ; Disable the mouse driver and return the previous int 33h handler address
  337.     PUBLIC    C    disableMouse
  338. PROC    C    disableMouse
  339.   mov    ax,001Fh
  340.   int    33h
  341.   cmp    ax,0FFFFh
  342.   je    @@Error
  343.   mov    dx,es
  344.   mov    ax,bx
  345.   retcode
  346.  
  347.       @@Error:
  348.   xor    dx,dx
  349.   xor    ax,ax
  350.   retcode
  351. ENDP
  352.  
  353. ; enables the mouse driver
  354. ; void enableMouse(void);
  355.     PUBLIC    C    enableMouse
  356. PROC    C    enableMouse
  357.   mov    ax,20h
  358.   int    33h
  359.   retcode
  360. ENDP
  361.  
  362. ; same as resetMouse(), but no initialization of mouse hardware
  363. ; void softResetMouse(void);
  364.     PUBLIC    C    softResetMouse
  365. PROC    C    softResetMouse
  366.   mov    ax,21h
  367.   int    33h
  368.   retcode
  369. ENDP
  370.  
  371. ; waits for the specified button to be released before returning
  372. ; void waitReleaseMouse(int button);
  373.     PUBLIC    C    waitReleaseMouse
  374. PROC    C    waitReleaseMouse
  375.     ARG    button:WORD
  376.   dec    [button]
  377.     @@L1:
  378.   mov    ax,3
  379.   int    33h
  380.   mov    cx,[button]
  381.   mov    dx,1
  382.   shl    dx,cl
  383.   and    bx,dx
  384.   or    bx,bx
  385.   jnz    @@L1
  386.   leave
  387.   retcode
  388. ENDP
  389.  
  390. ENDS
  391. END